package com.mzp.XbShop.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/view")
public class ViewController {
    @RequestMapping("/login")
    public String login(HttpServletRequest request) {
        request.getSession().removeAttribute("userInfo");
        return "login";
    }

    @RequestMapping("/logout")
    public String logout(HttpServletRequest request, HttpServletResponse response) {
        request.getSession().removeAttribute("userInfo");
        // 清除cookie
        Cookie cookie=new Cookie("userInfo","");
        cookie.setMaxAge(0);

        response.addCookie(cookie);
        return "login";
    }


    @RequestMapping("/test")
    public String test() {
        return "test";
    }

    /**
     * 跳转到主页
     *
     * @return
     */
    @RequestMapping("/home")
    public String home() {
        return "home";
    }

    /**
     * 个人中心
     *
     * @return
     */
    @RequestMapping("/profile")
    public String profile() {
        return "profile";
    }

    /**
     * 更改密码
     *
     * @return
     */
    @RequestMapping("/changePwd")
    public String changePwd() {
        return "changePwd";
    }

    /**
     * 注册账号
     *
     * @return
     */
    @RequestMapping("/register")
    public String register() {
        return "register";
    }

    /**
     * 跳转视图
     *
     * @return
     */
    @RequestMapping("/productList")
    public String productList() {
        return "productList";
    }

    /**
     * 商品详情
     * @return
     */
    @RequestMapping("/goodsDetail")
    public String goodsDetail() {
        return "goodsDetail";
    }

    /**
     * 购物车
     * @return
     */
    @RequestMapping("/car")
    public String car() {
        return "car";
    }

    /**
     *
     */
    @RequestMapping("/waitPay")
    public String waitPay() {
        return "waitPay";
    }
}
